
function saveItem(name, value) {
  localStorage.setItem(name, JSON.stringify(value))
}
export default {
  setSinger(state, singer) {
    state.singer = singer
  },
  setSongCover(state, songObj) {
    state.songCover = songObj
  },
  setAlbum(state, album) {
    state.album = album
  },
  setRank(state, rank) {
    state.rank = rank
  },
  setFullScreen(state, boolean) {
    state.fullScreen = boolean

  },
  setPlaying(state, boolean) {
    state.playing = boolean
  },
  setSequenceList(state, list) {
    state.sequenceList = JSON.parse(JSON.stringify(list))

  },
  setPlayList(state, list) {
    state.playList = JSON.parse(JSON.stringify(list));
  },
  setCurrentSong(state, currentSong) {
    state.currentSong = currentSong
  },
  setCurrentIndex(state, index) {

    state.currentIndex = index;

    state.currentSong = state.playList[index]

  },
  setMode(state, mode) {
    state.mode = mode
  },
  setValue(state, value) {
    state.value = value
  },
  setSongItem(state, item) {

    state.songItem = item

  },
  clearLoveMusic(state) {
    state.loveMusic = [];
    localStorage.removeItem('loveMusic')
  },
  clearHistoryPlay(state) {
    state.historyPlay = [];
    localStorage.removeItem('historyPlay')
  },
  unshiftLove(state, song) {
    state.loveMusic.unshift(song)
    saveItem('loveMusic', state.loveMusic)
  },
  removeLove(state, index) {
    state.loveMusic.splice(index, 1)
    saveItem('loveMusic', state.loveMusic)
  },
  clearHistroyQuery(state) {
    state.historyQuery = []
    localStorage.setItem('historyQuery', [])
  },
  setHistoryQuery(state, payload) {
    state.historyQuery = payload
    localStorage.setItem('historyQuery', JSON.stringify(payload))
  }
}